from pymt import *
import os
import gdata.photos.service
import gdata.media
import re
import subprocess
import threading
import random
from OpenGL.GL import *

class MTPicasaPictureWidget(MTScatterImage):
  def __init__(self, **kwargs):
    super(MTPicasaPictureWidget, self).__init__(**kwargs)
    print "MTPicasaPictureWidget constructed with filename:", self.filename
      
class PicasaSearch:
  def __init__(self, caller, keywords, number_of_images):
    self.number_of_images = number_of_images
    self.caller = caller
    self.search(keywords)

  def search(self, search_terms):
    print "Picasa.search"
    
    gd_client = gdata.photos.service.PhotosService()
    gd_client.email = "roomc78@gmail.com"
    gd_client.password = "mtouch1977"
    gd_client.source = 'uk.ac.napier.enice'
    gd_client.ProgrammaticLogin()

    for search_term in search_terms:
      photos = gd_client.SearchCommunityPhotos(search_term.lower(), limit=self.number_of_images)
    
    for photo in photos.entry:
      print "URL:", photo.content.src, "height:", int(photo.height.text), "width:", int(photo.width.text)
      self.caller.add_remote_image(photo.content.src)

